import React, { Component } from 'react'

export default class App extends Component {
  constructor() {
    super()

    this.state = {
      fruits: 'banana'
    }
  }

  render() {
    return (
      <div>
        <form onSubmit={e => this.handleSubmit(e)}>
          <select 
            name="fruits" 
            onChange={e => this.handleSlectChange(e)}
            //2. react中可以绑定value属性 指定默认值
            value={this.state.fruits} 
          >
            <option value="apple">苹果</option>
            <option value="banana">香蕉</option>
            {/* <option selected value="orange">橘子</option>  1.设置默认值*/}
            <option value="orange">橘子</option>
          </select>

          <input type="submit" value="提交" />
        </form>
      </div>
    )
  }

  handleSubmit(event) {
    //阻止默认行为
    event.preventDefault()

    console.log(this.state);
  }

  handleSlectChange(event) {
    this.setState({
      fruits: event.target.value
    })
  }
}
